<template>
  <div class="vip-container">
    <!-- 头部背景 -->
    <div class="header-bg"></div>

    <!-- 用户信息卡片 -->
    <div class="user-card">
      <div class="user-avatar">
        <img :src="user.userImg" alt="用户头像">
      </div>
      <div class="user-info">
        <h3>{{ user.userName }}</h3>
        <p class="user-id">ID: {{ user.userId }}</p>
        <div v-if="user.vip" class="vip-badge">
          <span>VIP会员</span>
          <p>有效期至 {{ user.expirationTime }}</p>
        </div>
        <div v-else class="vip-badge inactive">
          <span>普通用户</span>
        </div>
      </div>
    </div>

    <!-- 会员特权区域 -->
    <div class="vip-privileges">
      <h2 class="section-title"><i class="icon-crown"></i> 会员特权</h2>
      <div class="privilege-list">
        <div class="privilege-item">
          <i class="icon-benefit"></i>
          <div>
            <h3>透支额度提升</h3>
            <p>增加透支额度{{wallet.overdraftLimit}}元</p>
          </div>
        </div>
        <div class="privilege-item">
          <i class="icon-discount"></i>
          <div>
            <h3>专属优惠</h3>
            <p>享受会员专属折扣和优惠券</p>
          </div>
        </div>
        <div class="privilege-item">
          <i class="icon-delivery"></i>
          <div>
            <h3>快速配送</h3>
            <p>优先安排配送，更快收到订单</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 会员卡购买区域 -->
    <div class="membership-plans">
      <h2 class="section-title"><i class="icon-card"></i> 开通会员</h2>
      <div class="plan-grid">
        <div class="plan-card" @click="upgrade(2)">
          <div class="plan-header">
            <h3>月卡</h3>
            <div class="price">¥10</div>
          </div>
          <div class="plan-desc">30天会员特权</div>
          <div class="plan-save">日均¥0.33</div>
        </div>

        <div class="plan-card featured" @click="upgrade(3)">
          <div class="plan-badge">推荐</div>
          <div class="plan-header">
            <h3>季卡</h3>
            <div class="price">¥30</div>
          </div>
          <div class="plan-desc">90天会员特权</div>
          <div class="plan-save">日均¥0.33</div>
        </div>

        <div class="plan-card" @click="upgrade(4)">
          <div class="plan-header">
            <h3>半年卡</h3>
            <div class="price">¥60</div>
          </div>
          <div class="plan-desc">180天会员特权</div>
          <div class="plan-save">日均¥0.33</div>
        </div>

        <div class="plan-card" @click="upgrade(5)">
          <div class="plan-header">
            <h3>年卡</h3>
            <div class="price">¥120</div>
          </div>
          <div class="plan-desc">365天会员特权</div>
          <div class="plan-save">日均¥0.33</div>
        </div>
      </div>
    </div>

    <!-- 钱包余额 -->
    <div class="wallet-balance">
      <div class="balance-card">
        <div class="balance-header">
          <i class="icon-wallet"></i>
          <h3>钱包余额</h3>
        </div>
        <div class="balance-amount">¥{{ wallet.balance }}</div>
        <button class="recharge-btn">立即充值</button>
      </div>
    </div>

    <!-- 底部菜单部分 -->
    <Footer></Footer>
  </div>
</template>

<script>
import { ref, onMounted, getCurrentInstance } from 'vue';
import { useRouter } from 'vue-router';
import Footer from '../components/Footer.vue';
import axios from 'axios';
import qs from 'qs';
import router from '../router';

export default {
  name: 'VipMembership',
  setup() {
    const cns=getCurrentInstance();
    const user = ref({});
    const wallet = ref({});
    const {proxy}=getCurrentInstance();

    onMounted(() => {
      const getWalletInfo = async () => {
        try {
          const response = await axios.get(`WalletController/getWalletInfoById/${user.value.userId}`, qs.stringify({}));
          wallet.value = response.data;
        } catch (error) {
          console.error(error);
        }
      };
      user.value = proxy.$getSessionStorage('user');
      getWalletInfo();
    });

    const router = useRouter();

    const upgrade = async (status) => {
      router.push({ path: 'paymentExcludeOrders',query:{status} });
    };

    return{
      user,
      wallet,
      upgrade
    };
  },
  components:{
    Footer
  }
};
</script>

<style scoped>
.vip-container {
  font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
  background-color: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 70px; /* 为底部导航留出空间 */
  color: #333;
}

.header-bg {
  height: 150px;
  background: linear-gradient(135deg, #ff9500, #ff5e3a);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 0;
}

.user-card {
  background: white;
  border-radius: 12px;
  margin: 20px;
  padding: 20px;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  position: relative;
  z-index: 1;
  margin-top: 30px;
}

.user-avatar {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 15px;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-info {
  flex: 1;
}

.user-info h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.user-id {
  margin: 4px 0;
  font-size: 12px;
  color: #999;
}

.vip-badge {
  display: inline-block;
  background: linear-gradient(135deg, #ff9500, #ff5e3a);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  margin-top: 5px;
  font-weight: 500;
}

.vip-badge.inactive {
  background: #ccc;
}

.vip-badge span {
  display: inline-block;
  margin-right: 5px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin: 25px 20px 15px;
  display: flex;
  align-items: center;
}

.section-title i {
  margin-right: 8px;
  font-size: 20px;
  color: #ff9500;
}

.vip-privileges {
  background: white;
  border-radius: 12px;
  margin: 20px;
  padding: 15px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.privilege-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.privilege-item {
  display: flex;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background-color: #f9f9f9;
}

.privilege-item i {
  font-size: 24px;
  margin-right: 15px;
  color: #ff9500;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 149, 0, 0.1);
  border-radius: 50%;
}

.privilege-item h3 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
}

.privilege-item p {
  margin: 0;
  font-size: 13px;
  color: #666;
}

.membership-plans {
  background: white;
  border-radius: 12px;
  margin: 20px;
  padding: 15px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 10px;
}

.plan-card {
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 15px;
  position: relative;
  transition: all 0.3s ease;
}

.plan-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.plan-card.featured {
  border: 1px solid #ff9500;
  background: linear-gradient(to bottom, #fff8f0, white);
}

.plan-badge {
  position: absolute;
  top: -8px;
  right: 10px;
  background: #ff5e3a;
  color: white;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.plan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.plan-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.price {
  font-size: 18px;
  font-weight: 700;
  color: #ff5e3a;
}

.plan-desc {
  font-size: 12px;
  color: #999;
  margin-bottom: 8px;
}

.plan-save {
  font-size: 11px;
  color: #ff9500;
  font-weight: 500;
}

.wallet-balance {
  margin: 20px;
}

.balance-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.balance-header {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.balance-header i {
  font-size: 24px;
  color: #ff9500;
  margin-right: 10px;
}

.balance-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.balance-amount {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin: 20px 0;
  color: #333;
}

.recharge-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #ff9500, #ff5e3a);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.recharge-btn:hover {
  opacity: 0.9;
  transform: translateY(-2px);
}

/* 图标样式 - 可以使用实际图标字体或SVG替换 */
.icon-crown:before {
  content: "👑";
}
.icon-benefit:before {
  content: "💰";
}
.icon-discount:before {
  content: "🛍️";
}
.icon-delivery:before {
  content: "🚚";
}
.icon-card:before {
  content: "💳";
}
.icon-wallet:before {
  content: "👛";
}

/* 底部菜单样式 - 保持不变 */
.footer {
  width: 100%;
  height: 5vw;
  border-top: solid 1px #DDD;
  background-color: #fff;
  position: fixed;
  left: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
}
</style>